/*
 * @Author: zhuxiaoyi
 * @Date: 2024-01-22 16:57:20
 * @LastEditor: zhuxiaoyi
 * @LastEditTime: 2025-07-24 14:28:05
 * @Description:
 */
import {
  Body,
  Controller,
  Del,
  File,
  Get,
  Inject,
  Param,
  Post,
  Put,
  Query,
} from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { ApiBody, BodyContentType, ApiResponse, Type } from '@midwayjs/swagger';
import { AlgorithmService } from '../service/algorithm.service';
import { TaskDataResponseBody, ResponseBody, taskData } from '../types/ResponseBody'
import { GetAlgorithmsDto, UpdateAlgorithmsDto, TypeDto, taskDto, ResponseDto } from '../dto/AlgorithmDto';
import { ChangeFileMatchsDto, ChangeAutoDetectDto, VecChangeUnionDto, DetectDto,CreateAlgorithmDto } from '../dto/AlgorithmDto';
@Controller('/algorithm')
export class APIController {
  @Inject()
  ctx: Context;

  @Inject()
  algorithmService: AlgorithmService;

  @Post('/', { summary: '算法配置文件上传' })
  @ApiBody({
    description: '算法配置文件',
    contentType: BodyContentType.Multipart,
  })
  async create(@File() file: any) {
    return await this.algorithmService.createAlgorithm(file);
  }

  @Post('/add', { summary: '算法新增' })
  @ApiBody({
    description: '创建新的算法',
    type: CreateAlgorithmDto,
  })
  @ApiResponse({
    status: 201,
    description: '算法创建成功。',
    type: CreateAlgorithmDto,
  })
  @ApiResponse({
    status: 400,
    description: '请求参数错误。',
  })
  async createAlgorithm(@Body() createAlgorithmDto: CreateAlgorithmDto) {
    return await this.algorithmService.createAlgorithm1(createAlgorithmDto);
  }


  @Get('/', { summary: '算法列表' })
  async getList(@Query() params: GetAlgorithmsDto) {
    return await this.algorithmService.getAlgorithmList(params);
  }

  @Del('/:id', { summary: '删除算法' })
  async deleteAlgorithm(@Param('id') id: number) {
    return await this.algorithmService.deleteAlgorithm(id);
  }

  @Put('/:id', { summary: '更新算法' })
  @ApiBody({
    description: '更新算法的信息',
  })
  async updateAlgorithm(
    @Body() updateDto: UpdateAlgorithmsDto,
    @Param('id') id: number
  ) {
    return await this.algorithmService.updateAlgorithm(updateDto, id);
  }

  @Get('/:id', { summary: '执行算法' })
  async executeAlgorithm(@Param('id') id: number) {
    return await this.algorithmService.executeAlgorithm(id);  
  }

  @Get('/getAlgorithmById/:id', { summary: '执行算法' })
  async getAlgorithmById(@Param('id') id: number) {
    return await this.algorithmService.getAlgorithmById(id);
  }

  @Put('/setType/:id', { summary: '类型设置' })
  async setTypeById(@Param('id') id: number, @Body() typeParams: TypeDto,) {
    return await this.algorithmService.setTypeById(id, typeParams);
  }

}

@Controller('/customAlgorithm')
export class AlgorithmTypeController {
  @Inject()
  ctx: Context;

  @Inject()
  algorithmService: AlgorithmService;



  @Post('/ChangeFileMatchs/:id', { summary: '前后时相数据匹配' })
  @ApiResponse({
    status: 200,
    description: '成功',
    type: ResponseDto,
  })
  async ChangeFileMatchs(@Param('id') id: number, @Body() typeParams: ChangeFileMatchsDto): Promise<ResponseBody<taskData>> {
    return await this.algorithmService.customAlgorithm(id,typeParams);
  }

  @Post('/ChangeAutoDetect/:id', { summary: '智能变化检测' })
  @ApiResponse({
    status: 200,
    description: '成功',
    type: ResponseDto,
  })
  async ChangeAutoDetect(@Param('id') id: number, @Body() typeParams: ChangeAutoDetectDto) {
    return await this.algorithmService.customAlgorithm(id,typeParams);
  }

  @Post('/VecChangeUnion/:id', { summary: '成果合成导出' })
  @ApiResponse({
    status: 200,
    description: '成功',
    type: ResponseDto,
  })
  async VecChangeUnion(@Param('id') id: number, @Body() typeParams: VecChangeUnionDto) {
    return await this.algorithmService.customAlgorithm(id,typeParams);
  }

  @Post('/Detect/:id', { summary: '智能变化检测(单个文件)' })
  @ApiResponse({
    status: 200,
    description: '成功',
    type: ResponseDto,
  })
  async Detect(@Param('id') id: number, @Body() typeParams: DetectDto) {
    return await this.algorithmService.customAlgorithm(id,typeParams);
  }
}
